package com.wms_backend.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;

public class LogInterceptor implements HandlerInterceptor {

    private static final Logger logger = LoggerFactory.getLogger(LogInterceptor.class);
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler) throws Exception {

        String ipAddress = request.getRemoteAddr();
        String userAgent = request.getHeader("User-Agent");

        logger.info("Request from IP Address: {}", ipAddress);
        logger.info("User-Agent: {}", userAgent);

        // 继续执行请求
        return true;
    }

}
